package progress.exa30_1;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;

public class MethodStudy {
    public static void main(String[] args) throws InvocationTargetException, IllegalAccessException {
        MethodTest();
    }


    public static void MethodTest() throws InvocationTargetException, IllegalAccessException {
        Class<?> cl = ArrayList.class;
        ArrayList arrayList = new ArrayList();
        Method[] methods = cl.getDeclaredMethods();
        for(Method method:methods){
            System.out.println("方法名称"+method.getName());
            System.out.println("方法参数:");
            Class[] params = method.getParameterTypes();
            for(Class zl :params){
                System.out.print(zl.getName()+",");
            }
            System.out.println();
            System.out.print("返回参数：");
            System.out.println(method.getReturnType().getName());
            if(method.getName().equals("add")){
                if(params.length==1){
                    System.out.println("执行add(E e)方法，向数组添加Test");
                    method.invoke(arrayList,"Test");
                    System.out.println("查询数组的第一个元素"+arrayList.get(0));
                }
            }
        }

    }
}
